#!/bin/bash

echo "=== MQ学习项目 Docker启动脚本 ==="

# 检查Docker是否运行
if ! docker info > /dev/null 2>&1; then
    echo "错误: Docker未运行，请先启动Docker"
    exit 1
fi

# 检查Docker Compose是否可用
if ! docker-compose --version > /dev/null 2>&1; then
    echo "错误: Docker Compose未安装，请先安装Docker Compose"
    exit 1
fi

echo "正在启动所有MQ服务和Spring Boot应用..."

# 停止并删除现有容器
echo "清理现有容器..."
docker-compose down

# 构建并启动所有服务
echo "构建并启动所有服务..."
docker-compose up -d --build

# 等待服务启动
echo "等待服务启动..."
sleep 30

# 检查服务状态
echo "检查服务状态..."
docker-compose ps

echo ""
echo "=== 服务访问地址 ==="
echo "RabbitMQ管理界面: http://localhost:15672 (用户名: admin, 密码: admin123)"
echo "ActiveMQ管理界面: http://localhost:8161 (用户名: admin, 密码: admin123)"
echo "Pulsar管理界面: http://localhost:8080"
echo ""
echo "=== Spring Boot应用访问地址 ==="
echo "RabbitMQ应用: http://localhost:8081"
echo "Kafka应用: http://localhost:8082"
echo "RocketMQ应用: http://localhost:8083"
echo "ActiveMQ应用: http://localhost:8084"
echo "Pulsar应用: http://localhost:8085"
echo ""
echo "=== 测试命令示例 ==="
echo "测试RabbitMQ: curl -X POST http://localhost:8081/rabbitmq/send/direct"
echo "测试Kafka: curl -X POST http://localhost:8082/kafka/send/test"
echo "测试RocketMQ: curl -X POST http://localhost:8083/rocketmq/send/sync"
echo "测试ActiveMQ: curl -X POST http://localhost:8084/activemq/send/queue"
echo "测试Pulsar: curl -X POST http://localhost:8085/pulsar/send/sync"
echo ""
echo "=== 停止服务 ==="
echo "运行 'docker-compose down' 停止所有服务"
echo "运行 'docker-compose down -v' 停止服务并删除数据卷" 